package cc.fs.study.utils;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.util.DisplayMetrics;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.ViewConfiguration;

/**
 * 关于硬件
 * Created by fostion on 7/9/16.
 */
public class HardUtils {

    /**判断是否有虚拟键*/
    public static int getNavigationHeight(Context context) {
        boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey();
        boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
        Resources resources = context.getResources();
        int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
        if (resourceId > 0 && !hasMenuKey && !hasBackKey) {
            return resources.getDimensionPixelSize(resourceId);
        }
        return 0;
    }

    /**获取分辨率*/
    public static int[] getDeviceResolution(Activity context){
        DisplayMetrics dm = new DisplayMetrics();
        context.getWindowManager().getDefaultDisplay().getMetrics(dm);
        int width = dm.widthPixels;
        int height = dm.heightPixels;
        return new int[]{width,height};
    }

}
